package com.example.dellpc.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;


/**
 * Created by dellpc on 2016/8/11.
 */
public class FlowLayoutActivity extends Activity {
    private TagFlowLayout tagFlowLayout;
    private String[] datas;





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.flowlayoutactivity);
        initView();
    }

    public void initView() {
        ininDatas();
        tagFlowLayout= (TagFlowLayout) findViewById(R.id.id_flowlayout);
        tagFlowLayout.setMaxSelectCount(1);
        TagAdapter<String> adapter = new TagAdapter<String>(datas) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                LayoutInflater mInflater=LayoutInflater.from(getApplicationContext());
                TextView searchName = (TextView) mInflater.inflate(R.layout.search_flow_view, tagFlowLayout, false);
                searchName.setText(s);
                return searchName;
            }
        };
        tagFlowLayout.setAdapter(adapter);

        tagFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {

                Toast.makeText(getApplicationContext(),datas[position],Toast.LENGTH_LONG).show();

                return true;
            }
        });

    }

    public void ininDatas() {
       datas =new String[]{"AA","BB","BBc","BBAA","BBFDFDF","BDFSB","BDFDFB","BSDFB"};

    }




}
